package study.translation.interpreter;

import study.translation.parser.ParseTree;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

public class Subroutine
{
    private String name;

    private ParseTree.InnerNode block;

    private ParseTree.InnerNode variables;

    private ExecutionContext context;

    private Map<String, Argument> arguments = new LinkedHashMap<String, Argument>();

    public Subroutine( String name, ExecutionContext context )
    {
        this.name = name;
        this.context = context;
    }

    public void addArgument( Argument a )
    {
        arguments.put( a.getName(), a );
    }

    public Argument getArgument( String name )
    {
        return arguments.get( name );
    }

    public Collection<Argument> getArguments()
    {
        return arguments.values();
    }

    public int getArgumentCount()
    {
        return arguments.size();
    }

    public void setBlockNode( ParseTree.InnerNode node )
    {
        block = node;
    }

    public void setVariablesNode( ParseTree.InnerNode node )
    {
        variables = node;
    }

    public String getName()
    {
        return name;
    }

    public ParseTree.InnerNode getBlockNode()
    {
        return block;
    }

    public ParseTree.InnerNode getVariablesNode()
    {
        return variables;
    }

    public ExecutionContext getContext()
    {
        return context;
    }
}
